﻿using System.ComponentModel.DataAnnotations;

namespace com.iot.core.data
{
    public class Page<T>
    {
        public int TotalPage { get; set; } = 0;
        public int TotalRow { get; set; } = 0;
        [Range(1, int.MaxValue)]
        public int PageNumber { get; set; } = 0 ;
        [Range(1, int.MaxValue)]
        public int PageSize { get; set; } = 0;

        public List<T> Records { get; set; }

        public Page(int TotalRow,int PageNumber,int PageSize,List<T> Records=null)
        {
            this.TotalRow= TotalRow;
            this.PageNumber = PageNumber;
            this.PageSize  = PageSize;
            this.Records = Records;

            if (this.PageSize > 0)
            {
                this.TotalPage = this.TotalRow / this.PageSize;
                if (this.TotalRow % this.PageSize != 0)
                {
                    this.TotalPage++;
                }
            }
             
        }
    }
}
